package com.zto.sch.base.normal.jdk8;

import com.zto.sch.base.normal.domain.User;
import org.junit.Test;

import javax.jws.soap.SOAPBinding;
import java.util.Optional;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-04-27 18:36
 **/
public class OptionalTest {
    @Test
    public void test() {
        long id = 1;
        Optional<String> username = Optional
                .ofNullable(getUserById(id))
                .map(user -> user.getUsername())
                .map(name -> name.toLowerCase())
                .map(name -> name.replace('_', ' '));
        System.out.println("Username is: " + username.orElse("Unknown"));
    }

    private User getUserById(Long id) {
        User user = new User(2, "xiaoming");
        return null;
    }

}
